package cn.as142.controller;

import cn.as142.pojo.Teacher;
import cn.as142.pojo.Users;
import cn.as142.service.UserService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author XiaoMo
 * @Date 2022/3/3 11:25
 * @Version 1.0
 */
@RestController
public class UsersController {
    @Autowired
    private UserService userService;

    @Autowired
    private Teacher teacher;


    @GetMapping("/test")
    public String test(){
        return teacher.getTeacherName();
    }


    @PostMapping("/login")
    public String login(Users users){
        Map<String ,Object> map=new HashMap<>();
        String login = userService.login(users);
        if(login.equals("ok")){
            map.put("code",1000);
            map.put("msg","登录成功");
        }else {
            map.put("code",1005);
            map.put("msg","登录失败");
        }
        return JSON.toJSONString(map);
    }
}

